from django import template
from django.conf import settings
from django.utils.translation import gettext
from user.aai.signin import AAISignIn

register = template.Library()



@register.simple_tag
def get_aai_signin_name_url():
    tpaa = getattr(settings, 'THIRD_PARTY_APP_AUTH', {})
    tpaas = getattr(settings, 'THIRD_PARTY_APP_AUTH_SECURITY', {})
    if 'AAI' in tpaa and 'AAI' in tpaas:
        name = tpaa['AAI'].get('name', gettext('中国科技云身份认证联盟'))
        url = AAISignIn.get_signin_url()
        if url:
            return {'name': name, 'url': url}

    return None
